﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>ERP企业资源登录管理系统</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.11.2/dist/css/layui.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Rajdhani:wght@500;600;700&display=swap" rel="stylesheet">
</head>
<body>
    <style>
        body {
            background-color: #0a1929;
            margin: 0;
            padding: 0;
            font-family: 'Rajdhani', sans-serif, "Microsoft YaHei";
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            overflow: hidden;
        }

        /* 背景网格效果 */
        .tech-bg {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-image: 
                linear-gradient(rgba(8, 26, 45, 0.6) 1px, transparent 1px),
                linear-gradient(90deg, rgba(8, 26, 45, 0.6) 1px, transparent 1px);
            background-size: 30px 30px;
            background-position: center center;
            z-index: -2;
        }

        /* 背景辐射渐变 */
        .radial-bg {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 120vw;
            height: 120vw;
            background: radial-gradient(circle, rgba(10, 25, 41, 0.6) 0%, rgba(4, 12, 24, 1) 70%);
            z-index: -1;
        }

        /* 粒子动画 */
        .particles {
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: -1;
        }

        .particle {
            position: absolute;
            width: 2px;
            height: 2px;
            background-color: rgba(33, 150, 243, 0.5);
            border-radius: 50%;
            box-shadow: 0 0 3px #29B6F6;
            animation: float 4s infinite ease-in-out;
        }

        @@keyframes float {
            0%, 100% {
                transform: translateY(0) translateX(0);
                opacity: 0;
            }
            25% {
                opacity: 1;
            }
            75% {
                opacity: 0.5;
            }
        }

        .system-name {
            position: absolute;
            top: 10%;
            left: 50%;
            transform: translateX(-50%);
            color: #E1F5FE;
            font-size: 28px;
            font-weight: 700;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 2px;
            text-shadow: 0 0 10px rgba(33, 150, 243, 0.7), 0 0 20px rgba(33, 150, 243, 0.5);
            white-space: nowrap;
        }

        .system-subtitle {
            display: block;
            font-size: 16px;
            letter-spacing: 4px;
            color: #81D4FA;
            margin-top: 5px;
            font-weight: 500;
        }

        .demo-login-container {
            width: 340px;
            margin: 0 auto;
            background: rgba(15, 35, 60, 0.5);
            padding: 30px;
            border-radius: 12px;
            backdrop-filter: blur(10px);
            position: relative;
            box-shadow: 0 0 30px rgba(0, 0, 0, 0.3);
            color: #E1F5FE;
        }

        /* 霓虹边框效果 */
        .demo-login-container::after {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            border-radius: 14px;
            background: linear-gradient(45deg, #00b0ff, #3d5afe, #651fff, #00e5ff);
            z-index: -1;
            filter: blur(8px);
            opacity: 0.7;
        }

        .demo-login-other .layui-icon {
            position: relative;
            display: inline-block;
            margin: 0 2px;
            top: 2px;
            font-size: 26px;
        }

        .layui-form-item {
            margin-bottom: 20px;
        }

        .layui-input-wrap {
            background-color: rgba(15, 35, 60, 0.6);
            border-radius: 6px;
            border: 1px solid rgba(102, 204, 255, 0.3);
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .layui-input-wrap:hover {
            border-color: rgba(102, 204, 255, 0.5);
        }

        .layui-input-wrap:focus-within {
            border-color: #00b0ff;
            box-shadow: 0 0 15px rgba(0, 176, 255, 0.3);
        }

        .layui-input-prefix {
            background-color: rgba(10, 25, 41, 0.8);
            border-right: 1px solid rgba(102, 204, 255, 0.3);
        }

        .layui-input-prefix i {
            color: #81D4FA;
        }

        .layui-input {
            background-color: transparent;
            color: #E1F5FE;
            border: none;
            height: 42px;
            line-height: 42px;
        }

        .layui-form-checkbox[lay-skin=primary] {
            color: #B3E5FC;
        }

        .layui-form-checkbox[lay-skin=primary] i {
            border-color: rgba(102, 204, 255, 0.3);
            background-color: rgba(15, 35, 60, 0.6);
        }

        .layui-form-checkbox[lay-skin=primary]:hover i {
            border-color: #00b0ff;
        }

        .layui-form-checked[lay-skin=primary] i {
            border-color: #00b0ff;
            background-color: #00b0ff;
        }

        .layui-btn {
            background-color: #0288D1;
            height: 44px;
            line-height: 44px;
            font-size: 16px;
            font-weight: 600;
            letter-spacing: 1px;
            text-transform: uppercase;
            border-radius: 6px;
            box-shadow: 0 4px 15px rgba(2, 136, 209, 0.4);
            position: relative;
            overflow: hidden;
            transition: all 0.3s ease;
        }

        .layui-btn::after {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
            transition: 0.6s;
        }

        .layui-btn:hover {
            background-color: #039BE5;
            box-shadow: 0 6px 20px rgba(2, 136, 209, 0.6);
        }

        .layui-btn:hover::after {
            left: 100%;
        }

        .demo-login-other label {
            color: #90CAF9;
            font-size: 14px;
        }

        a {
            color: #29B6F6;
            text-decoration: none;
            transition: all 0.3s;
        }

        a:hover {
            color: #00b0ff;
            text-shadow: 0 0 8px rgba(0, 176, 255, 0.5);
        }

        /* 登录窗口顶部图标 */
        .login-header {
            text-align: center;
            margin-bottom: 25px;
        }

        .login-logo {
            width: 64px;
            height: 64px;
            background: linear-gradient(45deg, #00b0ff, #3d5afe);
            border-radius: 12px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 15px rgba(0, 176, 255, 0.5);
        }

        .login-logo i {
            font-size: 32px;
            color: white;
        }

        .login-title {
            margin-top: 15px;
            font-size: 20px;
            color: #E1F5FE;
            font-weight: 600;
        }
    </style>

    <!-- 技术背景 -->
    <div class="tech-bg"></div>
    <div class="radial-bg"></div>
    <div class="particles" id="particles"></div>

    <!-- 系统名称 -->
    <div class="system-name">
        ERP企业资源管理系统
        <span class="system-subtitle">ENTERPRISE RESOURCE PLANNING</span>
    </div>

    <form class="layui-form">
        <div class="demo-login-container">
            <div class="login-header">
                <div class="login-logo">
                    <i class="layui-icon layui-icon-console"></i>
                </div>
                <div class="login-title">用户登录</div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="username" value="" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="password" value="" lay-verify="required" placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <div class="layui-input-wrap">
                            <div class="layui-input-prefix">
                                <i class="layui-icon layui-icon-vercode"></i>
                            </div>
                            <input type="text" name="captcha" value="" lay-verify="required" placeholder="验证码" lay-reqtext="请填写验证码" autocomplete="off" class="layui-input" lay-affix="clear">
                        </div>
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="https://www.oschina.net/action/user/captcha" onclick="this.src='https://www.oschina.net/action/user/captcha?t='+ new Date().getTime();" style="border-radius: 4px; border: 1px solid rgba(102, 204, 255, 0.3); height: 38px;">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码">
                <a href="#forget" style="float: right; margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登 录 系 统</button>
            </div>
            <div class="layui-form-item demo-login-other">
                <label>社交账号登录</label>
                <span style="padding: 0 21px 0 6px;">
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-qq" style="color: #3492ed;"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat" style="color: #4daf29;"></i></a>
                    <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo" style="color: #cf1900;"></i></a>
                </span>
                或 <a href="#reg">注册帐号</a>
            </div>
        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
    <script src="//unpkg.com/layui@2.11.2/dist/layui.js"></script>
    <script>
        layui.use(['form', 'layer', 'util'], function(){
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;
            
            // 创建科技感粒子效果
            function createParticles() {
                const particlesContainer = document.getElementById('particles');
                const particleCount = 50;
                
                for (let i = 0; i < particleCount; i++) {
                    const particle = document.createElement('div');
                    particle.className = 'particle';
                    
                    // 随机位置
                    const x = Math.random() * 100;
                    const y = Math.random() * 100;
                    
                    // 随机大小
                    const size = Math.random() * 2 + 1;
                    
                    // 随机动画延迟和持续时间
                    const delay = Math.random() * 4;
                    const duration = Math.random() * 4 + 3;
                    
                    // 设置样式
                    particle.style.left = `${x}%`;
                    particle.style.top = `${y}%`;
                    particle.style.width = `${size}px`;
                    particle.style.height = `${size}px`;
                    particle.style.animationDelay = `${delay}s`;
                    particle.style.animationDuration = `${duration}s`;
                    
                    // 添加到容器
                    particlesContainer.appendChild(particle);
                }
            }
            
            // 初始化粒子效果
            createParticles();
            
            // 提交事件
            form.on('submit(demo-login)', function(data){
                var field = data.field; // 获取表单字段值
                
                // 验证码判断
                if (!field.captcha) {
                    layer.msg('请输入验证码', {
                        icon: 2,
                        time: 2000
                    });
                    return false;
                }
                
                // 发送登录请求到后端
                fetch('/RBAC/Login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded',
                    },
                    body: 'username=' + encodeURIComponent(field.username) + '&password=' + encodeURIComponent(field.password)
                })
                .then(response => response.json())
                .then(result => {
                    if (result.code === 0) {
                        // 保存用户信息到本地存储
                        if (result.data) {
                            // 记录返回的数据到控制台，方便调试
                            console.log('登录成功，服务端返回的原始数据:', result);
                            console.log('登录成功，用户数据详情:', JSON.stringify(result.data, null, 2));
                            
                            // 获取角色名称，不设置默认值
                            var roleName = null;
                            if (result.data.RoleName) {
                                roleName = result.data.RoleName;
                                console.log('从RoleName获取到角色:', roleName);
                            } else if (result.data.roleName) {
                                roleName = result.data.roleName;
                                console.log('从roleName获取到角色:', roleName);
                            } else {
                                console.log('警告：服务端未返回角色信息');
                            }
                            
                            // 保存到localStorage
                            var userInfo = {
                                id: result.data.Id || result.data.id,
                                userName: result.data.Username || result.data.username,
                                userNickname: result.data.UserNickname || result.data.userNickname || result.data.Username || result.data.username,
                                roleName: roleName
                            };
                            
                            console.log('保存到localStorage的用户信息:', userInfo);
                            localStorage.setItem('userInfo', JSON.stringify(userInfo));
                            
                            // 检查是否成功保存
                            try {
                                const savedData = localStorage.getItem('userInfo');
                                console.log('验证：从localStorage读取的数据:', savedData);
                                const parsedData = JSON.parse(savedData);
                                console.log('验证：解析后的数据:', parsedData);
                            } catch (e) {
                                console.error('保存用户信息时出错:', e);
                            }
                        } else {
                            console.warn('服务端返回的数据中没有用户信息');
                        }
                        
                        // 登录成功
                        layer.msg('登录成功', {
                            icon: 1,
                            time: 1000 //1秒后自动关闭
                        }, function(){
                            // 提示关闭后跳转到Index页面
                            window.location.href = '/Home/Index';
                        });
                    } else {
                        // 登录失败时刷新验证码
                        $('.layui-col-xs5 img').click();
                        // 清空验证码输入框
                        $('input[name="captcha"]').val('');
                        layer.msg(result.msg || '登录失败', {
                            icon: 2,
                            time: 2000
                        });
                    }
                })
                .catch(error => {
                    // 处理网络错误时刷新验证码
                    $('.layui-col-xs5 img').click();
                    // 清空验证码输入框
                    $('input[name="captcha"]').val('');
                    layer.msg('网络错误，请稍后重试', {
                        icon: 2,
                        time: 2000
                    });
                });
                
                return false; // 阻止默认 form 跳转
            });
        });
    </script>

</body>
</html>